#ifndef MKAHYPAR_SINGLE_NODE_HYPEREDGE_REMOVER_H
#define MKAHYPAR_SINGLE_NODE_HYPEREDGE_REMOVER_H
#include "mkahypar/utils/typedef.h"
#include "mkahypar/utils/defines.h"
//预处理提前把单点边缩合
namespace mkahypar{
  class SingleNodeHyperedgeRemover {
  public:
    struct RemovalResult {
      HyperedgeID num_removed_single_node_hes;
      HypernodeID num_unconnected_hns;
    };

    SingleNodeHyperedgeRemover() :
            _removed_hes() { }

    SingleNodeHyperedgeRemover(const SingleNodeHyperedgeRemover&) = delete;
    SingleNodeHyperedgeRemover& operator= (const SingleNodeHyperedgeRemover&) = delete;

    SingleNodeHyperedgeRemover(SingleNodeHyperedgeRemover&&) = delete;
    SingleNodeHyperedgeRemover& operator= (SingleNodeHyperedgeRemover&&) = delete;

    ~SingleNodeHyperedgeRemover() = default;

    RemovalResult removeSingleNodeHyperedges(Hypergraph& hypergraph) {
      RemovalResult result { 0, 0 };
      for (const HyperedgeID& he : hypergraph.edges()) {
//        LOG<<he<<hypergraph.edgeSize(he);
        if (hypergraph.edgeSize(he) == 1) {
          ++result.num_removed_single_node_hes;
          if (hypergraph.nodeDegree(*hypergraph.pins(he).first) == 1) {
            ++result.num_unconnected_hns;
          }
          hypergraph.removeEdge(he);
          _removed_hes.push_back(he);
        }
      }
      return result;
    }

    void restoreSingleNodeHyperedges(Hypergraph& hypergraph) {
      for (auto he_it = _removed_hes.rbegin(); he_it != _removed_hes.rend(); ++he_it) {
        hypergraph.restoreEdge(*he_it);
      }
      _removed_hes.clear();
    }

  private:
    std::vector<HyperedgeID> _removed_hes;
  };
}
#endif //MKAHYPAR_SINGLE_NODE_HYPEREDGE_REMOVER_H
